//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;

namespace OpenLS.UI
{
    partial class XPOfficeWindowResources
    {
        public XPOfficeWindowResources()
        {
            InitializeComponent();
        }
        void OnRestore(object sender, RoutedEventArgs args)
        {
            OnToggleWindowStateImp(sender, args);
        }
        void OnMinimize(object sender, RoutedEventArgs args)
        {
            FrameworkElement p = (FrameworkElement)sender;
            Window w = (Window)p.TemplatedParent;
            w.WindowState = WindowState.Minimized;
        }
        void OnToggleWindowState(object sender, MouseButtonEventArgs mouseButtonEventArgs)
        {
            OnToggleWindowStateImp(sender, mouseButtonEventArgs);
        }        
        void OnToggleWindowStateImp(object sender, EventArgs mouseButtonEventArgs)
        {
            try
            {
                Debug.WriteLine("OnToggleWindowState");
                var p = (FrameworkElement) sender;
                var w = (Window) p.TemplatedParent;
                if (w.WindowState == WindowState.Maximized)
                    w.WindowState = WindowState.Normal;
                else
                    w.WindowState = WindowState.Maximized;
            }
            catch(Exception e)
            {
                Debug.WriteLine(e);
                throw;
            }
        }
        void OnClose(object sender, RoutedEventArgs args)
        {
            FrameworkElement p = (FrameworkElement)sender;
            Window w = (Window)p.TemplatedParent;
            w.Close();
        }
      
        private void OnRectangleMouseDown(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement p = (DockPanel)sender;
            Window w = (Window)p.TemplatedParent;
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                w.DragMove();
                e.Handled = true;
            }
        }
    }
}
